package com.zuoban.service.strategy;

import com.zuoban.anno.LoginEnum;
import com.zuoban.anno.LoginStrategy;
import com.zuoban.common.Result;
import com.zuoban.dto.UserInfoDto;
import com.zuoban.dto.UserLoginDto;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

/**
 * @BelongsProject: zuoban-boot
 * @BelongsPackage: com.zuoban.service.strategy
 * @Author: zxy
 * @CreateTime: 2022-10-10
 * @Description: ...
 */
public interface LoginStrategyService {

    Result doLogin(HttpServletRequest request, UserLoginDto userLoginDto);

    default String getStrategyName(){
        return this.getClass().getAnnotation(LoginStrategy.class).name().getStrategy();
    };

    default void checkLoginCode(String name,int code){
        if (LoginEnum.ACCOUNT.getStrategy().equals(name)){
            if (LoginEnum.ACCOUNT.getCode() != code){
                throw new RuntimeException("账户策略编码校验异常，请检查编码后重新发起登录请求");
            }
        }
        if (LoginEnum.PHONE.getStrategy().equals(name)){
            if (LoginEnum.PHONE.getCode() != code){
                throw new RuntimeException("手机号策略编码校验异常，请检查编码后重新发起登录请求");
            }
        }
        if (LoginEnum.EMAIL.getStrategy().equals(name)){
            if (LoginEnum.EMAIL.getCode() != code){
                throw new RuntimeException("邮箱策略编码校验异常，请检查编码后重新发起登录请求");
            }
        }
        // ...以此类推
    }
}
